package com.sxt.core.model;

import com.sxt.core.anno.AutoBuilder;
import com.sxt.test.service.CupService;

/**
 * 对象的标签
 * 
 * @author Liushuangxi
 *
 */
@AutoBuilder
public class BeanLabel implements Comparable<BeanLabel> {
	// 对象的唯一名称
	private String name;

	// 对象的接口
	private Class<?> interfaces;

	/**
	 * 通过对象名称得到对象标签
	 * 
	 * @param name
	 * @return
	 */
	public static BeanLabel of(String name) {
		BeanLabel beanLabel = new BeanLabel();
		beanLabel.setName(name);
		return beanLabel;
	}

	/**
	 * 通过对象接口得到对象标签
	 * 
	 * @param interfaces
	 * @return
	 */
	public static BeanLabel of(Class<?> interfaces) {
		BeanLabel beanLabel = new BeanLabel();
		beanLabel.setInterfaces(interfaces);
		return beanLabel;
	}

	/**
	 * 通过对象接口和名称得到对象标签
	 * 
	 * @param interfaces
	 * @param name
	 * @return
	 */
	public static BeanLabel of(Class<?> interfaces, String name) {
		BeanLabel beanlabel = new BeanLabel();
		beanlabel.setInterfaces(interfaces);
		beanlabel.setName(name);
		return beanlabel;
	}

	@Override
	public int compareTo(BeanLabel o) {
		if (o.getName() != null && this.getName() != null) {
			return o.getName().compareTo(this.getName());
		}
		if (o.getInterfaces() != null && this.getInterfaces() != null) {
			return o.getInterfaces().getName().compareTo(this.getInterfaces().getName());
		}
		throw new RuntimeException("标签对象的id和接口都为null");
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Class<?> getInterfaces() {
		return interfaces;
	}

	public void setInterfaces(Class<?> interfaces) {
		this.interfaces = interfaces;
	}

	public static void main(String[] args) {
		BeanLabel lable = BeanLabel.of(CupService.class, "cupServiceImpl");
		BeanLabel of = BeanLabel.of("cupServiceImpl");
		System.out.println(lable);
		System.out.println(of);
		BeanLabel of2 = BeanLabel.of(CupService.class);
		System.out.println(of2);
		System.out.println(lable.compareTo(of));
		System.out.println(lable.compareTo(of2));
	}

}
